export const SET_BASIC_INDICATOR_PREIVEW_LIST = 'setBasicIndicatorPreviewList';
export const GET_BASIC_INDICATOR_PREIVEW_LIST = 'getBasicIndicatorPreviewList';
export const GENERATE_COMPOSITE_INDICATOR_PREVIEW = 'generateCompositeIndicatorPreview'
export const SET_GENERATED_COMPOSITE_VISUALIZATION_CODE = "setGeneratedCompositeVisualizationCode";

// To set the current theme to either dark or light
export const setBasicIndicatorPreviewList = (value) => ({
  type: SET_BASIC_INDICATOR_PREIVEW_LIST,
  value
});

export const getBasicIndicatorPreviewList = () => ({
  type: GET_BASIC_INDICATOR_PREIVEW_LIST
});

export const generateCompositeIndicatorPreview = (queryBuilder) => ({
  type: GENERATE_COMPOSITE_INDICATOR_PREVIEW,
  payload: {
    queryBuilder
  }
})
export const setGeneratedCompositeVisualizationCode = (divData, scriptData, errorMessage) => ({
  type: SET_GENERATED_COMPOSITE_VISUALIZATION_CODE,
  payload: {
    divData,
    scriptData,
    errorMessage
  }
})
// Initial state for User Preferences
const initialState = {
  baiscIndicatorPreviewList: []
};

export default function userPreferencesReducer(state = initialState, action) {
  switch (action.type) {
    // Themes
    case SET_BASIC_INDICATOR_PREIVEW_LIST:
      return {
        ...state, baiscIndicatorPreviewList: action.value
      }
      case SET_GENERATED_COMPOSITE_VISUALIZATION_CODE: {
        return {
          ...state,
          fetchedData: {
            ...state.fetchedData,
            visualizationCode: {
              ...state.visualizationCode,
              displayCode: action.payload.divData ? action.payload.divData : "",
              scriptCode: action.payload.scriptData ? action.payload.scriptData : "",
              errorMessage: action.payload.errorMessage ? action.payload.errorMessage : "",
            }
          }
        }
      }
      default:
        return state;
  }
}